<?php
    require("../models/webconfig.php");
    require("../models/class.connection.php");
    require("../models/entities/class.ProductEntity.php");
    require("../models/repositories/class.ProductRepository.php");
    require("../models/entities/class.CategoryEntity.php");
    require("../models/repositories/class.CategoryRepository.php");
    require("../models/entities/class.SectionEntity.php");
    require("../models/repositories/class.SectionRepository.php");
    $productRepository = new ProductRepository();
    $categoryRepository = new CategoryRepository();
    $sectionRepository = new SectionRepository();
    $result;
    if(isset($_GET['code']))
        $result = $productRepository->GetDetail($_GET['code']);
    else
        exit("Khong tim thay thong tin san pham");
        
    function GetListProductImages($imgSrc)
    {
        if(isset($imgSrc))
        {
            if ($imgSrc != "")
            {
                return explode("|", $imgSrc);
            }
        }
        return null;
    }
    $arrImages = GetListProductImages($result->ImageSrc_s);
    $category = $categoryRepository->GetCategory($result->CategoryID_i);
    $section = $sectionRepository->GetSection($category->SectionID_i);
?>
<style type="text/css">
.dialogTitleLeft
{
    font-weight:bold;
    width:150px;
    border:1px solid #d1d1d1;
    color:#f47a0e;
    text-align:center;
}

.dialogContentRight
{
    border: 1px solid #d1d1d1;
    text-align:left;
}
</style>
<span id="productCode" style="display: none;" code="<?php echo $result->Code_s; ?>"></span>
    <fieldset style="margin: 10px; padding:5px; font-size:12px; font-family: Tahoma;">
        <legend style="font-weight:bold; padding:10px; color:Teal: font-size:13px">Chi tiết sản phẩm</legend>
        <table style="width:690px; border:1px solid #d1d1d1; line-height:25px;">
            <tr>
                <td class="dialogTitleLeft">Tên sản phẩm</td>
                <td class="dialogContentRight">
                    <span style="font-weight: bold; margin:12px 0 0 18px;"><?php echo $result->Name_s; ?></span>
                </td>
            </tr>
            <tr>
                <td class="dialogTitleLeft">Màu sắc</td>
                <td class="dialogContentRight">
                    <span style="font-weight: bold; margin:12px 0 0 18px; text-align: left;"><?php echo $result->Color_s; ?></span>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="border: 1px solid #d1d1d1;">
                    <div style="font-weight: bold; padding-top:5px; padding-bottom:5px;"> Danh sách hình ảnh sản phẩm </div>
                    <div style='margin-bottom: 20px;'>
                        <table style="width: 685px; border: 1px solid #d1d1d1;">
                            <tr style="font-weight: bold; border: 1px solid #d1d1d1;">
                                <td style="border: 1px solid #d1d1d1; color:#f47a0e;padding-top:5px; padding-bottom:5px;">STT</td>
                                <td style="border: 1px solid #d1d1d1; color:#f47a0e;padding-top:5px; padding-bottom:5px;">Hình ảnh</td>
                            </tr>
                            <?php
                                if(isset($arrImages))
                                {
                                    for($i = 0; $i < count($arrImages); $i++){
                            ?>
                            <tr style="font-weight: bold;">
                                <td style="border: 1px solid #d1d1d1;"><?php echo ($i + 1); ?></td>
                                <td style="text-align:center;border: 1px solid #d1d1d1;">
                                    <img src="../content/images/Products/<?php echo $result->Code_s . '/' . $arrImages[$i] ?>" style="max-height: 120px; max-width: 120px; border: 1px solid #d1d1d1;" />
                                </td>
                            </tr>               
                            <?php
                                    }
                                }
                            ?>
                        </table>
                </td>
            </tr>
            <tr>
                <td class="dialogTitleLeft">Loại sản phẩm</td>
                <td class="dialogContentRight">
                    <span style="margin:12px 0 0 18px;"><?php echo $category->Name_s . " (". $section->Name_s .")"; ?></span>
                </td>
            </tr>
            <tr>
                <td class="dialogTitleLeft">Mô tả</td>
                <td class="dialogContentRight">
                    <span style="margin:12px 0 0 18px;"><?php echo $result->Description_s; ?></span>
                </td>
            </tr>
            <tr>
                <td class="dialogTitleLeft">Ngày đăng</td>
                <td class="dialogContentRight">
                <?php
                    date_default_timezone_set('UTC');
                    $date = date_create($result->PostedDay_dt);
                ?>
                    <span style="margin:12px 0 0 18px;"><?php echo date_format($date, "d/m/Y H:i:s"); ?></span>
                </td>
            </tr>
            <tr>
                <td class="dialogTitleLeft">Giá</td>
                <td class="dialogContentRight">
                    <span style="margin:12px 0 0 18px;"><?php echo number_format($result->Price_f); ?></span>
                </td>
            </tr>
            <tr>
                <td class="dialogTitleLeft">Đã bán</td>
                <td class="dialogContentRight">
                    <span style="margin:12px 0 0 18px;"><?php echo number_format($result->Bought_i) . " sản phẩm"; ?></span>
                </td>
            </tr>
        </table>
    </fieldset>
